/*
 * ClientConnect.h
 *
 *  Created on: Aug 17, 2016
 *      Author: ubuntu
 */

#ifndef CLIENTCONNECT_H_
#define CLIENTCONNECT_H_

#include "TcpServer.h"
#include "DataInfo.h"

class TcpServer;

class ClientConnection {
public:
	ClientConnection(TcpServer *m_pParent, struct connectop *op, struct sockaddr *addr);
	virtual ~ClientConnection();

	virtual void on_read();
	virtual void on_close();
	virtual void sendBuf(unsigned char *buf, size_t len);
	virtual time_t getLastTime();
	virtual time_t getConnTime();

protected:
	virtual bool parsePackage(unsigned char *buf, size_t len, int add_head, int add_tail);
	virtual void recv_data_output(unsigned char *buf, size_t len);
	virtual void pushDataInfo(DataInfo *pDataInfo);

protected:
	struct connectop *m_op;
	TcpServer *m_pParent;
	int m_fd;
	struct sockaddr m_addr;
	bool m_bTerminated;
	time_t tm_conn;
	time_t tm_last;
	int add_head;
	int add_tail;
	int add_len;
};

#endif /* CLIENTCONNECT_H_ */
